package net.java.mediasearch.exception;

/**
 * OfdbMediaSearchContentException.
 */
public class OfdbMediaSearchContentException extends MediaSearchException {
	
	private static final long serialVersionUID = -3897458372492311030L;
	
	// ResultCodes bound to OFDB-Statuscodes
	public static final int RESULTCODE_OK = 0;
	public static final int RESULTCODE_UNKOWN_ERROR = 1;
	public static final int RESULTCODE_ERROR_OR_TIMEOUT = 2;
	public static final int RESULTCODE_NO_OR_UNKNOWN_OFDB_ID = 3;
	public static final int RESULTCODE_NO_DATA_FOUND = 4;
	public static final int RESULTCODE_DATA_REQUEST_ERROR = 5;
	public static final int RESULTCODE_SERVICE_MAINTENANCE = 9;
	
	// Own Resultcodes
	public static final int RESULTCODE_XML_PARSE_ERROR = 101;
	
	
	private int resultCode;
	
	/**
	 * Standard-Constructor.
	 */
	public OfdbMediaSearchContentException() {
		super();
	}
	
	/**
	 * Extended Constructor.
	 * 
	 * @param msg String
	 */
	public OfdbMediaSearchContentException(String message) {
		super(message);
	}
	
	/**
	 * Extended Constructor.
	 * 
	 * @param message String
	 * @param throwable Throwable
	 */
	public OfdbMediaSearchContentException(String message, Throwable throwable) {
		super(message, throwable);
	}
	
	/**
	 * Extended Constructor.
	 * 
	 * @param resultCode int
	 */
	public OfdbMediaSearchContentException(int resultCode) {
		setResultCodeForValue(resultCode);
	}
	
	public OfdbMediaSearchContentException(int resultCode, String message, Throwable throwable) {
		super(message, throwable);
		setResultCodeForValue(resultCode);
	}
	
	// TODO Diskussionspunkt: Ev. sollten wir die method umschreiben, dass hier auch gleich ne Basis-Msg in die message-variable gesetzt wird.
	//   dann sollte diese Methode auch umbenannt werden, und in zukunft nur mehr im Konstruktor, und nicht mehr in der set()-methode verwendet werden
	private void setResultCodeForValue(int value) {
		switch (value) {
		case RESULTCODE_OK:
			this.resultCode = RESULTCODE_OK;
			break;
		case RESULTCODE_ERROR_OR_TIMEOUT:
			this.resultCode = RESULTCODE_ERROR_OR_TIMEOUT;
			break;
		case RESULTCODE_NO_OR_UNKNOWN_OFDB_ID:
			this.resultCode = RESULTCODE_NO_OR_UNKNOWN_OFDB_ID;
			break;
		case RESULTCODE_NO_DATA_FOUND:
			this.resultCode = RESULTCODE_NO_DATA_FOUND;
			break;
		case RESULTCODE_DATA_REQUEST_ERROR:
			this.resultCode = RESULTCODE_DATA_REQUEST_ERROR;
			break;
		case RESULTCODE_SERVICE_MAINTENANCE:
			this.resultCode = RESULTCODE_SERVICE_MAINTENANCE;
			break;
		case RESULTCODE_XML_PARSE_ERROR:
			this.resultCode = RESULTCODE_XML_PARSE_ERROR;
			break;
		default:
			this.resultCode = RESULTCODE_UNKOWN_ERROR;
			break;
		}
	}

	public int getResultCode() {
		return resultCode;
	}

	/**
	 * Special Set-Method.
	 * 
	 * @param resultCode int
	 */
	public void setResultCode(int resultCode) {
		setResultCodeForValue(resultCode);
	}
}
